// pages/report/index.js
const app = getApp()
import {
    util,
    Toast,
    Dialog,
    commonMixin
} from "../../utils/util.js";
Page({
    behaviors: [commonMixin],

    /**
     * 页面的初始数据
     */
    data: {
        showPopup: false,
        userArray: [
            {
                name: '',
                sex: 1,
            }
        ],
        selectIndex: 0,
        showUser: false, //选人弹框
        orderList: [],
        statusOptions: [],
    },
    selectUser() {
        this.setData({
            showPopup: true,
            showUser: true
        })
    },
    onClose() {
        this.setData({
            showPopup: false,
            showUser: false
        })
    },
    selectNode(e) {
        let index = e.currentTarget.dataset.index;
        this.setData({
            selectIndex: index,
            showPopup: false,
            showUser: false
        });
        this.getOrderList();
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        
    },

    getCheckers() {
        util.http.post("v1/mini/family-users",{}).then((res) => {
            if (res.data.code == 0) {
              this.setData({
                userArray: res.data.data
              })
              if (res.data.data.length <= this.data.selectIndex + 1) {
                this.setData({
                  selectIndex: res.data.data.length - 1
                })
              }
              this.getOrderList();
            }
        }).catch((err) => {
            wx.hideLoading();
            Toast('网络异常！刷新后重试！');
            console.log(err)
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      let userInfo = util.getUserInfo()
      if (!userInfo.status) {
        app.globalData.loginFlag = true;
        this.navToUrl('/pages/my/index');
      }
        // this.getOrderList();
        this.getCheckers();
    },

    onTabItemTap(item) {
      console.log('点击了tab项', item);
      let userInfo = util.getUserInfo()
      if (!userInfo.status) {
        app.globalData.loginFlag = true;
        this.navToUrl('/pages/my/index');
      }
    },

    onSelectPerson() {

    },

    getOrderList() {
        wx.showLoading({
          title: '加载中',
        })
        util.http.post("v1/mini/sample-get-list",{
            checker_id: this.data.userArray[this.data.selectIndex].id,
            status: 4
        }).then((res)=>{
            let list = res.data.data.list;
            this.setData({
                orderList: list,
                statusOptions: res.data.data.status,
            });
            wx.hideLoading();
        }).catch((err)=>{
            wx.hideLoading();
            Toast('网络异常！刷新后重试！');
            console.log(err)
        })
    },

    handleJumpCheck(event) {
        wx.navigateTo({
          url: '/pages/check/index?id=' + event.currentTarget.dataset.id,
        })
    },

    handleOpenPdf(event) {
        let url = event.currentTarget.dataset.url;
        util.openPdf(url);
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})